package algorithm;

/**
 * 101. 对称二叉树
 * @author Panbo Guo
 * @date 2021/7/15
 */
public class T00101 {

    public static void main(String[] args) {
        Integer[] arr = new Integer[]{1,2,2,null,3,null,3};
        System.out.println(new Solution().isSymmetric(TreeUtils.buildTree(arr)));
    }

    static class Solution {
        public boolean isSymmetric(TreeNode root) {
            if (root == null)
                return true;
            return isSymmetric(root.left, root.right);
        }

        public boolean isSymmetric(TreeNode p, TreeNode q) {
            if (p == null)
                return q == null;
            if (q == null)
                return false;
            return p.val == q.val && isSymmetric(p.left, q.right) && isSymmetric(p.right, q.left);
        }
    }
}
